package com.zhuss.core.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.core.db.dao.ext.UserRoleDao;
import com.zhuss.core.db.entity.UserRole;

/**
 * 查询用户、角色关系 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("userRoleRead")
public class UserRoleRead {
	
	@Autowired
	private UserRoleDao userRoleDao;
	
	
	/**
	 * 根据用户查询角色列表ID
	 * @param userId
	 * @return
	 */
	public Object listRoleId(Long userId) {
		List<Long> result = userRoleDao.listRoleId(userId);
		return result;
	}
	
	/**
	 * 根据角色查询用户列表
	 * @param userId
	 * @return
	 */
	public Object listUserId(Long roleId) {
		List<UserRole> userList = userRoleDao.listUser(roleId);
		List<Long> userIdList = new ArrayList<Long>();
		transferUser(userList, userIdList);
		return userIdList;
	}
	
	/**
	 * 根据角色ID列表查询用户列表
	 * @param userId
	 * @return
	 */
	public List<Long> listUserIdByRoleList(List<Long> roleIdList) {
		List<UserRole> userList = userRoleDao.listUserIdByRoleList(roleIdList);
		List<Long> userIdList = new ArrayList<Long>();
		transferUser(userList, userIdList);
		return userIdList;
	}

	private void transferUser(List<UserRole> userList,
			List<Long> userIdList) {
		for (UserRole item : userList) {
			userIdList.add(item.getUserId());
		}
		
	}
	
	

}
